<?php
add_action('widgets_init', 'register_like_social_wg_widget'); // load widget

function register_like_social_wg_widget() { // register widget
    register_widget('like_social_wg');
}

class like_social_wg extends WP_Widget {// widget class {

    function like_social_wg() { 
    // widget setting | class name must be same function name
        $widget_ops = array('classname' => 'like-social', 'description' =>
            'Display top Category Home page');
        $control_ops = array(
            'width' => 250,
            'height' => 350,
            'id_base' => 'like_social_wg');
        $this->WP_Widget('like_social_wg', 'CouponX - Like Social', $widget_ops, $control_ops);
    }

    function widget($args, $instance) {
        $fb_page = get_option('fb_page');
        $gg_plus = get_option('gg_plus');
        $twitter = get_option('twitter');
        ?>
        <div class="row-fluid social_box module">
            <div class="row-fluid title">
                <p>Like us with</p>
            </div>
            <div class="row-fluid social_wrap">
                <div class="social social_fb">
                    <div class="fb">
                        <div class="fb-like" data-href="<?php echo $fb_page;?>" 
                            data-width="450" data-layout="box_count" 
                            data-show-faces="false" data-send="false">
                        </div>
                    </div>
                </div>
                <div class="social social_plus">
                    <div class="gplus">
                         <script type="text/javascript">
                                (function() {
                                  var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true;
                                  po.src = 'https://apis.google.com/js/plusone.js';
                                  var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s);
                                })();
                         </script>
                             <g:plusone size="tall" href="<?php echo $gg_plus;?>"></g:plusone>
                    </div>
                </div>
                <div class="social social_twitter">
                    <a href="<?php echo $twitter;?>" class="twitter-share-button twitter-count-vertical" data-count="vertical">Tweet</a>
                    <script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0],p=/^http:/.test(d.location)?'http':'https';
                        if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src=p+'://platform.twitter.com/widgets.js';
                            fjs.parentNode.insertBefore(js,fjs);}}(document, 'script', 'twitter-wjs');</script>
                </div>
            </div>
        </div>
            <?php
                if(is_singular('store') || is_home() || is_tax('event') || is_tax('store_category')){
                        $url = explode('?', cpx_current_url());
                    ?>
<!--                    <div class="share-us">
                        <p>And Share us</p>
                        <a class="button-fb-share" onclick="Share.facebook('<?php echo $url[0];?>')">
                            <img src="<?php echo get_template_directory_uri().'/img/logo/facebook-share.jpg';?>" alt="share-facebook"/>
                        </a>
                        <a class="button-g-share" href="https://plus.google.com/share?url={<?php echo $url[0];?>}" onclick="javascript:window.open(this.href,
                            '', 'menubar=no,toolbar=no,resizable=yes,scrollbars=yes,height=600,width=600');return false;"><img
                            src="https://www.gstatic.com/images/icons/gplus-64.png" alt="Share on Google+"/></a>
                    </div>-->
                    
                <?php }
            ?>
                 
    <?php }

    function update($new_instance, $old_instance) { // update widget
        $instance = $old_instance;
        $instance['title'] = $new_instance['title'];

        return $instance;
    }

    function form($instance) { // form for the widget options
        ?>
        <div style="color: #333;">
        </div>
        <?php
    }
}
?>
